package com.learn.scrm;

import cn.hutool.core.util.PhoneUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.Builder;
import lombok.Data;
import org.apache.commons.io.IOUtils;

import java.nio.charset.Charset;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toCollection;

/**
 * @author : Yu.Tan
 * @date : 2022/11/10 15:53
 * @desc : **
 */
public class OptionTest {
    public static void main(String[] args) {
////        List<CrmRoleDto> roleShopList=new ArrayList<>();
////        List<String> sqlRoles=new ArrayList<>(16);
////        CrmRoleDto crmRoleDto=new CrmRoleDto();
////        crmRoleDto.setDealerShopNo("130628");
////        roleShopList.add(crmRoleDto);
////
////        CrmRoleDto crmRoleDto1=new CrmRoleDto();
////        crmRoleDto1.setDealerShopNo("130629");
////        roleShopList.add(crmRoleDto1);
////
////        String sqlTpl = "(t.shop_id = '%s' %s)";
////        String s = String.format(sqlTpl, "1231", "");
////        System.out.println(s);
//
//
//        List<String> list=new ArrayList<>();
//        list.add("不停车电子收费系统");
//        list.add("不停车电子收费系统1");
//        list.add("缝线样式-B");
//        list.add("缝线样式-B1");
//
//        List<String> list2=new ArrayList<>();
//        list2.add("缝线样式-B");
//        list2.add("不停车电子收费系统1");
//        list2.add("不停车电子收费系统");
//        list2.add("缝线样式-B1");
//
//        List<String> list1 = list.stream().sorted().collect(Collectors.toList());
//        String join = String.join(",", list1);
//        System.out.println(join);
//
//        List<String> listStr1 = list2.stream().sorted().collect(Collectors.toList());
//        String join1 = String.join(",", listStr1);
//        System.out.println(join1);

        String options=
                "6扬声器,方向盘电加热,副驾驶:4方向电动,感应式电动后背门,后搁物板,记忆辅助/锁车自动折叠/电动调节/除霜/转向灯,驾驶员:6方向+记忆辅助+迎宾座椅,前排座椅加热,前排座椅通风+前排座椅按摩,全景天窗,声纹脸部识别"
                ;
        String[] split = options.split(",");
        List<String> list = Arrays.asList(options.split(","));
        List<ProductOption> productOptions = list.stream().map(r -> {
            ProductOption productOption = new ProductOption();
            productOption.setOptionName(r);
            return productOption;
        }).collect(Collectors.toList());
        JSON json = JSON.parseObject(JSON.toJSONString(productOptions), JSON.class);

        System.out.println(json);

        try {
            String  mockTxt = IOUtils.toString(ProductOption.class.getResourceAsStream("/json/OlaOrder.json"), String.valueOf(Charset.defaultCharset()));
            List<ProductOption> optionList = JSON.parseArray(mockTxt, ProductOption.class);
//            System.out.println(optionList);

            String collect = productOptions.stream().map(ProductOption::getOptionName).sorted().distinct().collect(Collectors.joining(","));
            String collect1 = optionList.stream().map(ProductOption::getOptionName).sorted().distinct().collect(Collectors.joining(","));

            System.out.println(collect);
            System.out.println(collect1);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.toString());
        }


//        DistributeCarRequest distributeCarRequest=new DistributeCarRequest();
//
//        System.out.println(distributeCarRequest.isFromVms());


//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("ceshi1","13198789098");
//        jsonObject.put("ceshi2","13198789098");
//        jsonObject.put("ceshi3","13198789098");
//        jsonObject.put("ceshi4","13198789098");
//        System.out.println(jsonObject.toJSONString());
//
//        LinkUser user = LinkUser.builder().linkName("测试1").linkPhone("13109890987").build();

        List<LinkUser> linkUsers=new ArrayList<>();
        linkUsers.add(LinkUser.builder().linkName("测试1").linkPhone("13109890987").build());
        linkUsers.add(LinkUser.builder().linkName("测试2").linkPhone("13109890987").build());
        linkUsers.add(LinkUser.builder().linkName("测试3").linkPhone("13109890987").build());
        linkUsers.add(LinkUser.builder().linkName("测试4").linkPhone("13109890987").build());
        linkUsers.add(LinkUser.builder().linkName("测试5").linkPhone("13109890987").build());
        System.out.println(JSON.toJSONString(linkUsers));

        List<LinkUser> studentList = linkUsers.stream().collect(
                collectingAndThen(
                        toCollection(() -> new TreeSet<>(Comparator.comparing(LinkUser::getLinkPhone))), ArrayList::new)
        );
        System.out.println(JSON.toJSONString(studentList));

        List<LinkUser> collect = linkUsers.stream().distinct().collect(Collectors.toList());
        System.out.println(JSON.toJSONString(collect));
        boolean mobile = PhoneUtil.isMobile(null);
        System.out.println(mobile);



        String s="00000001,00000009";
        String[] split1 = s.split(",");
        List<String> strings = Arrays.asList(split1);
        for (String string : strings) {
            System.out.println(string);
        }
    }

    @Data
    @Builder
    static class LinkUser{
        private String linkName;
        private String linkPhone;
    }
}
